package com.easyardemo.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.View;

import com.easyardemo.app.AppConstant;
import com.easyardemo.tools.manager.AppManager;
/**
 * createTime：2019/2/26/026 on 9:47
 *
 * @author: jyc dell
 */
public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener {

    protected Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().addActivity(this);
        this.mContext = BaseActivity.this;
        if(AppConstant.Screen.width == 0){
            Display defaultDisplay = getWindowManager().getDefaultDisplay();
            Point point = new Point();
            defaultDisplay.getSize(point);
            AppConstant.Screen.width = point.x;
            AppConstant.Screen.height = point.y;
        }
    }


    protected void intentTo(Class activity) {
        intentTo(new Intent(BaseActivity.this, activity));
    }

    protected void intentTo(Intent intent) {
        startActivity(intent);
    }

    protected void intentSingleTo(Class activity) {
        Intent intent = new Intent(BaseActivity.this, activity);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intentTo(intent);
    }

    public void closeActivity() {
        finish();
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    protected void onDestroy() {
        AppManager.getAppManager().finishActivity(this);
        super.onDestroy();
    }
}
